package com.dayu.web.controller.basic;

import java.util.List;

import com.dayu.common.annotation.RepeatSubmit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dayu.common.annotation.Log;
import com.dayu.common.core.controller.BaseController;
import com.dayu.common.core.domain.AjaxResult;
import com.dayu.common.enums.BusinessType;
import com.dayu.basic.domain.BasicSupplier;
import com.dayu.basic.service.IBasicSupplierService;
import com.dayu.common.utils.poi.ExcelUtil;
import com.dayu.common.core.page.TableDataInfo;

/**
 * 供应商管理Controller
 * 
 * @author HK
 * @date 2021-04-15
 */
@RestController
@RequestMapping("/basic/supplier")
public class BasicSupplierController extends BaseController
{
    @Autowired
    private IBasicSupplierService basicSupplierService;

    /**
     * 查询供应商管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BasicSupplier basicSupplier)
    {
        startPage();
        List<BasicSupplier> list = basicSupplierService.selectBasicSupplierList(basicSupplier);
        return getDataTable(list);
    }

    /**
     * 导出供应商管理列表
     */
    @PreAuthorize("@ss.hasPermi('basic:supplier:export')")
    @Log(title = "供应商管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BasicSupplier basicSupplier)
    {
        List<BasicSupplier> list = basicSupplierService.selectBasicSupplierList(basicSupplier);
        ExcelUtil<BasicSupplier> util = new ExcelUtil<BasicSupplier>(BasicSupplier.class);
        return util.exportExcel(list, "supplier");
    }

    /**
     * 获取供应商管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:supplier:query')")
    @GetMapping(value = "/{supplierId}")
    public AjaxResult getInfo(@PathVariable("supplierId") Long supplierId)
    {
        return AjaxResult.success(basicSupplierService.selectBasicSupplierById(supplierId));
    }

    /**
     * 新增供应商管理
     */
    @PreAuthorize("@ss.hasPermi('basic:supplier:add')")
    @Log(title = "供应商管理", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody BasicSupplier basicSupplier)
    {
        return toAjax(basicSupplierService.insertBasicSupplier(basicSupplier));
    }

    /**
     * 修改供应商管理
     */
    @PreAuthorize("@ss.hasPermi('basic:supplier:edit')")
    @Log(title = "供应商管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicSupplier basicSupplier)
    {
        return toAjax(basicSupplierService.updateBasicSupplier(basicSupplier));
    }

    /**
     * 删除供应商管理
     */
    @PreAuthorize("@ss.hasPermi('basic:supplier:remove')")
    @Log(title = "供应商管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{supplierIds}")
    public AjaxResult remove(@PathVariable Long[] supplierIds)
    {
        return toAjax(basicSupplierService.deleteBasicSupplierByIds(supplierIds));
    }
}
